package common;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

//This class will have all the utility functions, for now only the DB connection function is added.
public class Utilities {

	public void connectoDB () {

		System.out.println("Trying to connect to the database...... ****");
		String dbtime;
		String dbUrl = "jdbc:mysql://localhost:3306/myseleniumdb";
		String dbClass = "com.mysql.jdbc.Driver";
		String query = "Select * FROM person";
	
		
		try {

			Class.forName(dbClass);
			Connection con = DriverManager.getConnection(dbUrl, "root", "");
			Statement stmt = con.createStatement();
			ResultSet rs = stmt.executeQuery(query);

			while (rs.next()) {
				dbtime = rs.getString("fname");
				System.out.println(dbtime);
			} //end while

			con.close();
		} //end try
		catch(ClassNotFoundException e) {
			e.printStackTrace();
		}
		catch(SQLException e) {
			e.printStackTrace();
		}
		
		System.out.println("Trying to connect to the database...... ****");
		
	}
	
	
}
